package oicon;
//JPopupMenu Example
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

class PopupMenuExample {

   static JPopupMenu menu = new JPopupMenu("Popup");

   static void addItem(final String s) {
      JMenuItem item = new JMenuItem(s);
      item.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            System.out.println(e.getActionCommand()+" selected");}
      });
      menu.add(item);
   }

   public static void main(String[] args) {
      JPanel panel = new JPanel();
      panel.addMouseListener(new MouseAdapter() {
         public void mousePressed(MouseEvent e) {
            if(e.isPopupTrigger())
               menu.show(e.getComponent(),e.getX(),e.getY());
         }
         public void mouseReleased(MouseEvent e) {
            if(e.isPopupTrigger())
               menu.show(e.getComponent(),e.getX(),e.getY());
         }
      });

      addItem("item a");addItem("item b");addItem("item c");
      JFrame frame = new JFrame();
      Container cp = frame.getContentPane();
      cp.add(panel);
      frame.setSize(200,100);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);
   }
}